<!--
  权限表添加页面
  User: 高祥
  Date: 2020-02-13
-->
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >

    <div id="tree_1" class="tree-demo">
        <ul>
            <li data-jstree='{ "opened" : true ,"icon" : "fa fa-asterisk fa-spin icon-state-info"}' data-id="0" data-name="顶级目录">
                顶级权限（Root）
                <ul>
                        <li  th:each="data,iterStat : ${permissionList}" th:data-id="${data.id}" th:data-jstree="'{\'icon\':\''+${data.icon}+'\'}'">
                            <span th:text="${data.name}"></span>
                            <ul th:if="${data.permissions.size() > 0}">
                                   <li th:each="data2,iterStat2 : ${data.permissions}" th:data-id="${data2.id}"  th:data-jstree="${data2.dataJsTree }">
                                        <span th:text="${data2.name}"></span>
                                        <ul th:if="${data2.permissions.size() > 0}">
                                            <li th:each="data3,iterStat3 : ${data2.permissions}" th:data-id="${data3.id}"  th:data-jstree="${data3.dataJsTree }">
                                                <span th:text="${data3.name}"></span>
                                            </li>
                                        </ul>
                                    </li>
                            </ul>
                        </li>
                </ul>
            </li>
        </ul>
    </div>

    <script>

        $("#tree_1").ready(function(){
            $("#tree_1").jstree({
                'plugins': [ "checkbox", "types"],
                "core" : {
                    "themes" : {
                        "responsive": false
                    }
                }
            });
        });

        /**
         * 获取全部选中节点
         */
        function getAllCheckedPower(){
            var checkedArray = new Array();

            /**
             * 获取选中节点
             * */
            var checkeds = $('#tree_1').jstree().get_checked(true);
            for(var c in checkeds){
                checkedArray.push(checkeds[c].data["id"]);
            }

            /**
             * 获取父级节点
             */
            $("#tree_1").find("li").each(function(){
                var lii = $(this).find("a").eq(0).find("i").eq(0);
                if(lii.hasClass("jstree-undetermined")){
                    var id = $(this).data("id");
                    if(id != undefined){
                        checkedArray.push(id);
                    }
                }
            });

            return checkedArray;
        }
    </script>
</html>